//
//  HelpHandler.swift
//  ECApp
//
//  Created by 程平 on 2017/10/22.
//

import Foundation
import PerfectHTTP
extension Handler{
    
   private static func parameterError(_ request: HTTPRequest, _ response: HTTPResponse){
        let errorJsonString = ResponseData.jsonData(resultCode: ResultCode.parmeterError, data: nil)
      
        do {
            try response.setBody(json: errorJsonString)
            response.completed()
        } catch let error {
            print("设置body出错了")
        }
    }
    
    static func checkParmeter(key:String,_ request: HTTPRequest,_ response: HTTPResponse) ->String? {
        if let value = request.param(name: key)  {
            return value
        }else{
            parameterError(request, response)
        }
        return nil
    }
}
